<template>
  <div>
    <i
      class="iconfont icon-fullscreen screenfull-svg"
      @click="changeScreen"
    ></i>
  </div>
</template>

<script>
import ScreenFull from "screenfull";
export default {
  name: "Screenfull",
  data() {
    return {
      isFullscreen: false
    };
  },
  created() {},
   mounted() {
    this.init();
  },
  computed: {},
  components: {},
  methods: {
    //   改变全屏
    changeScreen() {
         if (!screenfull.enabled) {
        this.$message({
          message: "you browser can not work",
          type: "warning",
        });
        return false;
      }
      screenfull.toggle();
    //   if (!ScreenFull.isEnabled) {
    //     // 此时全屏不可用
    //     this.$message.warning("此时全屏组件不可用");
    //     return;
    //   }
    //   // document.documentElement.requestFullscreen()  原生js调用
    //   //   如果可用 就可以全屏
    //   ScreenFull.toggle();
    },
     change() {
      this.isFullscreen = screenfull.isFullscreen;
    },
    init() {
      if (screenfull.enabled) {
        screenfull.on("change", this.change);
      }
    },
    destroy() {
      if (screenfull.enabled) {
        screenfull.off("change", this.change);
      }
    },
  }
};
</script>

<style lang="less" scoped>
.screenfull-svg {
  //  display: inline-block;
  cursor: pointer;
  color: #fff;
  width: 20px;
  height: 20px;
}
</style>